// 引入express框架
const express = require('express');
const fs = require('fs');

const promisify = fn => (...args) => new Promise((resolve, reject) => {
    fn(...args, (err, data) => {
        if (err) reject(err)
        resolve(data)
    })
})
const readFile = promisify(fs.readFile)
    // 创建网站服务器
const app = express();

app.get('/index', async(req, res, next) => {
    await readFile('./demo.txt')
});

// 错误处理中间件
app.use((err, req, res, next) => {
    res.status(500).send(err.message);
});

// 监听端口
app.listen(3000);
console.log('网站服务器启动成功');